<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
  <head>
    <base href="<%=basePath%>">
    <%@ taglib uri="/struts-tags" prefix="s"%>
    <%@include file="./headMeta.jsp" %>
  </head>
  <body class="skin-blue">
    <%@include file="./header.jsp" %>
    <div class="wrapper row-offcanvas row-offcanvas-left">
        <!-- Left side column. contains the logo and sidebar -->
        <%@include file="./sidebar.jsp" %>

      <!-- Right side column. Contains the navbar and content of the page -->
      <aside class="right-side">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                商品
            </h1>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-md-6">
                    <div class="box box-primary">
                        <div class="box-header">
                        <h3 class="box-title">${ptname!=null?ptname:"商品"}列表</h3>
                            <div class="box-tool" style="margin: 7px 7px 0 0;">
                                <ul class="pagination pagination-sm no-margin pull-right">
                                    <li><a href="javascript:void(0)">&laquo;</a></li>
                                    <li><a href="javascript:void(0)">1</a></li>
                                    <li><a href="javascript:void(0)">2</a></li>
                                    <li><a href="javascript:void(0)">3</a></li>
                                    <li><a href="javascript:void(0)">&raquo;</a></li>
                                </ul>
                            </div>
                        </div><!-- /.box-header -->
                        <div class="box-body no-padding">
                            <table class="table table-striped">
                                <tr>
                                    <th style="width: 15%">商品编号</th>
                                    <th>名称</th>
                                    <th>单价</th>
                                    <th>类型</th>
                                    <th>在售</th>
                                    <th style="width: 15%"></th>
                                </tr>
                                <s:iterator value="#listproduct" status="st">
                                  <tr>
                                    <td>${pid}</td>
                                    <td>${pname }</td>
                                    <td>${price}</td>
                                    <td>${typeList.get(st.index).ptname }</td>
                                    <td>${onSale=="true" ? "是" : "否" }</td>
                                    <td><a href="product/manageProduct.action?pid=${pid }" class="btn btn-primary btn-xs">编辑</a></td>
                                    <%-- <td><a href="product/delProduct.action?pid=${pid }" class="btn btn-primary btn-xs">删除</a></td> --%>
                                  </tr>
                                </s:iterator>
                            </table>
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!-- /.col -->
                <div class="col-md-6">
                    <!-- general form elements -->
                    <div class="box box-primary">
                        <div class="box-header">
                            <h3 class="box-title">添加${ptname!=null?ptname:"商品"}</h3>
                        </div><!-- /.box-header -->
                        <!-- form start -->
                        <form role="form" action="product/addProduct.action" method="post" id="pfrm">
                            <div class="box-body">
                                <div class="form-group">
                                    <label for="inputUsername">名称</label>
                                    <input type="text" name="pname" class="form-control validate[require]" id="inputUsername" placeholder="请输入商品名称" data-title="商品名称" />
                                </div>
                                <div class="form-group">
                                    <label for="inputPwd">价格</label>
                                    <input type="text" name="price" class="form-control validate[require,plus&0]" id="inputPwd" placeholder="请输入商品价格" data-title="商品价格" />
                                </div>
                                <div class="form-group">
                                    <label>在售</label>
                                    <select class="form-control" name="onSale">
                                        <option value="1" selected>是</option>
                                        <option value="0">否</option>
                                    </select>
                                </div>
                                <s:if test="#parameters.ptid==null">
                                  <div class="form-group">
                                      <label>类型</label>
                                      <select class="form-control" name="ptid">
                                          <s:iterator value="#listproductType" status="st">
                                            <option value="${ptid }">${ptname }</option>
                                          </s:iterator>
                                      </select>
                                  </div>
                                </s:if>
                                <s:else>
                                  <input type="text" name="ptid" value="${ ptid}"/  style="display:none;">
                                </s:else>
                            </div><!-- /.box-body -->

                            <div class="box-footer">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </form>
                    </div><!-- /.box -->
                </div>
            </div><!-- /.row -->
        </section><!-- /.content -->   
      </aside>
    </div><!-- ./wrapper -->
  </body>
  <%@include file="./javascript.jsp" %>
  <script src="resource/js/validate.js" type="text/javascript"></script>
<script>
		validate.initValidate("pfrm");
		
		$("#pfrm").submit(function(){
			if(validate.validate("pfrm") == false){
				alert(validate.error);
				return false;
			}
		});
		
	</script>
</html>
